package models;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Artist {
	private String pgid;
	private String tier;
	private String artist;
	private String act_yrs;
	private String existence_year;
	private String born_form_place;
	private String ceased_year;
	private String ceased_place;
	private String amgid;
	private String born_name;
	private String is_solo;
	private ArrayList<Artist>artistInfluencerList;
	private SubStyle subStyle;
	private int existence_year_int;
	private int ceased_year_int;
	private int windowId;
	
	
	
	
	public Artist(String pgid, String tier, String artist, String act_yrs,
			String existence_year, String born_form_place, String ceased_year,
			String ceased_place, String amgid, String born_name, String is_solo) {
		super();
		this.pgid = pgid;
		this.tier = tier;
		this.artist = artist;
		this.act_yrs = act_yrs;
		this.existence_year = existence_year;
		this.born_form_place = born_form_place;
		this.ceased_year = ceased_year;
		this.ceased_place = ceased_place;
		this.amgid = amgid;
		this.born_name = born_name;
		this.is_solo = is_solo;
		artistInfluencerList= new ArrayList<Artist>();
		this.windowId=-2;
		
		existence_year_int= this.getYearFromString(this.existence_year,true);
		ceased_year_int= this.getYearFromString(this.ceased_year,false);
		
	}
	
	public String getPgid() {
		return pgid;
	}
	public void setPgid(String pgid) {
		this.pgid = pgid;
	}
	public String getTier() {
		return tier;
	}
	public void setTier(String tier) {
		this.tier = tier;
	}
	public String getArtist() {
		return artist;
	}
	public void setArtist(String artist) {
		this.artist = artist;
	}
	public String getAct_yrs() {
		return act_yrs;
	}
	public void setAct_yrs(String act_yrs) {
		this.act_yrs = act_yrs;
	}
	public String getExistence_year() {
		return existence_year;
	}
	public void setExistence_year(String existence_year) {
		this.existence_year = existence_year;
	}
	public String getBorn_form_place() {
		return born_form_place;
	}
	public void setBorn_form_place(String born_form_place) {
		this.born_form_place = born_form_place;
	}
	public String getCeased_year() {
		return ceased_year;
	}
	public void setCeased_year(String ceased_year) {
		this.ceased_year = ceased_year;
	}
	public String getCeased_place() {
		return ceased_place;
	}
	public void setCeased_place(String ceased_place) {
		this.ceased_place = ceased_place;
	}
	public String getAmgid() {
		return amgid;
	}
	public void setAmgid(String amgid) {
		this.amgid = amgid;
	}
	public String getBorn_name() {
		return born_name;
	}
	public void setBorn_name(String born_name) {
		this.born_name = born_name;
	}
	public String getIs_solo() {
		return is_solo;
	}
	public void setIs_solo(String is_solo) {
		this.is_solo = is_solo;
	}
	public int getExistence_year_int() {
		return existence_year_int;
	}
	public void setExistence_year_int(int existence_year_int) {
		this.existence_year_int = existence_year_int;
	}
	public int getCeased_year_int() {
		return ceased_year_int;
	}
	public void setCeased_year_int(int ceased_year_int) {
		this.ceased_year_int = ceased_year_int;
	}

	@Override
	public String toString() {
		String influencedList="";
		for(int i=0; i<artistInfluencerList.size();i++){
			try {
				influencedList+= artistInfluencerList.get(i).getArtist();
				
				if(i!=artistInfluencerList.size()-1){
					influencedList+="-";
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		
		}
		
		String subStyleString="NO STYLE";
		if(subStyle!=null){
			subStyleString=subStyle.getName()+" @ "+subStyle.getMajorStyle().getName();
			
		}
		return "Artist [pgid=" + pgid + ", tier=" + tier + ", artist=" + artist
				+ ", act_yrs=" + act_yrs + ", existence_year=" + existence_year
				+ ", born_form_place=" + born_form_place + ", ceased_year="
				+ ceased_year + ", ceased_place=" + ceased_place + ", amgid="
				+ amgid + ", born_name=" + born_name + ", is_solo=" + is_solo
				+ ", artistInfluencerList=" + influencedList
				+ ", subStyle=" + subStyleString + ", Start Year="+ existence_year_int+ ", Final Year="+ ceased_year_int+", Window Id="+ windowId+"]";
	}

	public void addArtistInfluencer(Artist a){
		artistInfluencerList.add(a);
	}
	

	public void setSubStyle(SubStyle subStyle) {
		this.subStyle = subStyle;
	}

	public SubStyle getSubStyle() {
		return subStyle;
	}
	
	public ArrayList<Artist> getArtistInfluencerList() {
		return artistInfluencerList;
	}

	public void setArtistInfluencerList(ArrayList<Artist> artistInfluencerList) {
		this.artistInfluencerList = artistInfluencerList;
	}
	
	public int getYearFromString(String s, boolean startYear){
		int year;
		if(startYear){
			year=1950;
		}
		else{
			year=2010;
		}
		
		Pattern p=Pattern.compile("(\\d{4})");
		Matcher m=p.matcher(s);
		while(m.find()){
		   year=Integer.valueOf(m.group(1));
		}
		
		return year;
	}

	public int getWindowId() {
		return windowId;
	}

	public void setWindowId(int windowId) {
		this.windowId = windowId;
	}
	
	public String getDetail(){
		
		
		String influencedList="\r\n";
		for(int i=0; i<artistInfluencerList.size();i++){
			try {
				influencedList+= artistInfluencerList.get(i).getArtist();
				
				if(i!=artistInfluencerList.size()-1){
					influencedList+="\r\n";
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		
		}
		
		String subStyleString="NO STYLE";
		if(subStyle!=null){
			subStyleString=subStyle.getName()+" @ "+subStyle.getMajorStyle().getName();
			
		}
		
		return "Pgid: " + pgid + "\r\nTier: " + tier + "\r\nArtist name: " + artist
			+ "\r\nActive years: " + act_yrs + "\r\nExistence Year: " + existence_year
			+ "\r\nBorn from: " + born_form_place + "\r\nCeased year: "
			+ ceased_year + "\r\nCeased place: " + ceased_place + "\r\nAmgid: "
			+ amgid + "\r\nBorn name: " + born_name + "\r\nSolo: " + is_solo
			+ "\r\nSubStyle: " + subStyleString+"\r\nInfluencers: "+ influencedList;
	}
	
}
